(function ($) {
	var me = {};
	window.Basis = Class.create({
		// 继承的父类
		//Extends: Animal,
		// 混入的集合
		//Mixes: EventMixin,
		// 静态方法
		//Statics: {},
		// 构造
		constructor: function(element, options){
			this.element = $(element);
			me = this;
			$.each(options,function(k,v){
				if( v == undefined && v == null ) return true;
				if( typeof v === 'object' ) {
					$.extend(me.get(k),v);
				} else {
					me.set(k,v);
				}
			});
		},
		// 设置
		set: function(key,val){
			this[key] = val;
			return this;
		},
		// 获取
		get: function(key){
			return this[key];
		},
		// 是否自动加载
		autoLoad: true,
		// ID前缀 - 必填
		prefixId: "",
		// 接口地址前缀 - 必填
		apiPathPrefix: "",
		// 创建Element
		load: function(){},
		// 加载数据前操作
		beforeLoad: function(){},
		// 加载数据之后操作
		afterLoad: function(){},
		// 弹出框信息
		showMsg: function(message, buttons){
			var buttons = buttons || ['success'];
			var btnConfig = {
				success: {
					label: "确定",
					className: "btn-sm btn-primary",
					callback: function(){
					}
				},
				cancel: {
					label: "取消",
					className: "btn-sm",
				}
			};
			var dialogOption = {
				message: message,
				buttons: {}
			};
			$.each(buttons,function(key,val){
				if( typeof val == 'object' ) {
					dialogOption.buttons[val] = val;
				} else if( typeof val == 'string' ) {
					dialogOption.buttons[val] = btnConfig[val];
				}
			});
			bootbox.dialog(dialogOption);
		},
		// a=1&b=2转换成{a:1,b:2}
		paramString2obj: function(params){
			var array = params.split("&");
			var obj = {};
			for (var i = 0, len = array.length; i < len; i++) {
				var item = array[i].split("=");
				obj[item[0]] = item[1];
			}
			return obj;
		},
		// {a:1,b:2}转换成a=1&b=2
		obj2paramString: function(obj){
			return $.param(obj);
		},
		// url参数
		urlParams: {},
		// 获取url参数
		getUrlParams: function(){
			me = this;
			var url = window.location.href, pos = url.indexOf('?'), params = url.substring(pos+1,url.length);
			var result = {};
			if( pos != -1 ) {
				result = me.urlParams = me.paramString2obj(params);
			}
			return result;
		},
		// 返回访问地址
		getUrl: function(url){
			url = ( url.indexOf("//") == -1 ? me.apiPathPrefix : '') + url;
			return url;
		},
		// json对象转excel文件
		jsonToExcel: function( data ){
			var data = data || {}, filename = me.prefixId + (new Date()).format("yyyyMMddhhmmssS") + ".xlsx", ws_name = "Sheet1";
			var wb = XLSX.utils.book_new(), ws = XLSX.utils.json_to_sheet(data);
			XLSX.utils.book_append_sheet(wb, ws, ws_name);
			XLSX.writeFile(wb, filename);
		},
	});

})(jQuery);


